using System;
using MagicLightProbes;
using UnityEngine;
using UnityEditor;

namespace com.yoozoo.gta.Art
{
    public class TrainStationTool : MonoBehaviour
    {
        [SerializeField] [Header("奇观世界位置")]
        public Vector3 trainStationWorldPositions;

        [SerializeField] [Header("奇观世界位置偏移")] private Vector3 trainStationWorldPositionsOffset;

        [SerializeField] [Header("奇观世界范围半径")] public float trainStationWorldPositionRadius = 2;

        [SerializeField] [Header("奇观世界范围半径扩展")]
        public float trainStationWorldPositionOutRadius = 1;

        void Update()
        {
            trainStationWorldPositions = transform.position + trainStationWorldPositionsOffset;
            Shader.SetGlobalVector("_TrainPosition", trainStationWorldPositions);
            Shader.SetGlobalVector("_TrainScope",
                new Vector2(trainStationWorldPositionRadius,
                    trainStationWorldPositionRadius + trainStationWorldPositionOutRadius));
        }
    }

#if UNITY_EDITOR
    [CustomEditor(typeof(TrainStationTool))]
    public class ArrowExampleEditor : Editor
    {
        protected virtual void OnSceneGUI()
        {
            TrainStationTool trainStationTool = (TrainStationTool)target;
            
            Vector3 position = trainStationTool.trainStationWorldPositions;
            float radius = trainStationTool.trainStationWorldPositionRadius;
            float outRadius = radius + trainStationTool.trainStationWorldPositionOutRadius;

            // 画线
            Handles.color = Color.green;
            Handles.DrawLine(position, position + new Vector3(outRadius, 0, 0));
            Handles.DrawLine(position, position + new Vector3(0, outRadius, 0));
            Handles.DrawLine(position, position + new Vector3(0, 0, outRadius));
            Handles.DrawLine(position, position + new Vector3(-outRadius, 0, 0));
            Handles.DrawLine(position, position + new Vector3(0, -outRadius, 0));
            Handles.DrawLine(position, position + new Vector3(0, 0, -outRadius));

            // 画内圆
            Handles.color = Color.red;
            Handles.DrawWireArc(position, Vector3.up, Vector3.forward, 360, radius);
            Handles.DrawWireArc(position, Vector3.right, Vector3.back, 180, radius);
            Handles.DrawWireArc(position, Vector3.forward, Vector3.right, 180, radius);

            // 画外圆
            Handles.color = Color.green;
            Handles.DrawWireArc(position, Vector3.up, Vector3.forward, 360, outRadius);
            Handles.DrawWireArc(position, Vector3.right, Vector3.back, 180, outRadius);
            Handles.DrawWireArc(position, Vector3.forward, Vector3.right, 180, outRadius);
        }
    }
#endif
}